﻿#include "CardControl.h"

#include <iostream>

using namespace Views::Helpers::Graphic;

CardControl::CardControl()
	: Control(), is_selected(false)
{
}

void CardControl::setShape()
{
	Shape = sf::Shape::Rectangle(0, 0, 200, 50, sf::Color(100, 128, 128));
}

void CardControl::setText()
{
}

void CardControl::select()
{
	is_selected = true;
	Shape.SetColor(selectedColour);
}

void CardControl::unselect()
{
	is_selected = false;
	if (has_mouse_over)
		Shape.SetColor(hoverColour);
	else
		Shape.SetColor(standardColour);
}

template<typename T>
GenericCardControl<T>::GenericCardControl(T* card)
	: card(card), CardControl()
{
	setColours();
	setShape();
	setCardShape();
	setText();
}

template<typename T>
void GenericCardControl<T>::setSelectable()
{
	is_selectable = true;
}

template<typename T>
T* GenericCardControl<T>::getCard()
{
	return card;
}

void CardControl::MouseEnter()
{
	Control::MouseEnter();
	if (is_selectable && !is_selected)
		Shape.SetColor(hoverColour);
}

void CardControl::MouseLeave()
{
	Control::MouseLeave();
	if (is_selectable && !is_selected)
		Shape.SetColor(standardColour);
}

template<typename T>
void GenericCardControl<T>::setText()
{
	Text = new Utils::GUI::Label(card->getTitle(), Utils::GUI::Label::CENTER, Utils::GUI::Label::MIDDLE);
	Text->SetTextWidth(GetWidth());
	Text->SetTextHeight(GetHeight());
	addChild(Text);
}

template<typename T>
void GenericCardControl<T>::setCardShape()
{
	Shape.SetColor(standardColour);
}

template<>
void GenericCardControl<Cards::PlayerCard>::setColours()
{
	standardColour = sf::Color(232, 27, 76, 255);
	hoverColour = sf::Color(232, 89, 123, 255);
	selectedColour = sf::Color(231, 117, 61, 255);
}

template<>
void GenericCardControl<Cards::WeaponCard>::setColours()
{
	standardColour = sf::Color(242, 23, 41, 255);
	hoverColour = sf::Color(242, 71, 85, 255);
	selectedColour = sf::Color(232, 71, 141, 255);
}

template<>
void GenericCardControl<Cards::RoomCard>::setColours()
{
	standardColour = sf::Color(229, 65, 27, 255);
	hoverColour = sf::Color(242, 71, 85, 255);
	selectedColour = sf::Color(232, 71, 141, 255);
}

template<>
CardControl* CardControlFactory::create(Cards::Card* card)
{
	if (dynamic_cast<Cards::PlayerCard*>(card) != NULL)
	{
		return CardControlFactory::create(dynamic_cast<Cards::PlayerCard*>(card));
	}
	else if (dynamic_cast<Cards::WeaponCard*>(card) != NULL)
	{
		return CardControlFactory::create(dynamic_cast<Cards::WeaponCard*>(card));
	}
	else if (dynamic_cast<Cards::RoomCard*>(card) != NULL)
	{
		return CardControlFactory::create(dynamic_cast<Cards::RoomCard*>(card));
	}
	else
	{
		return NULL;
	}
}

template<typename T>
CardControl* CardControlFactory::create(T* card)
{
	return new GenericCardControl<T>(card);
}

